//
//  User.swift
//  Status
//
//  Created by 花轮 on 15/5/18.
//  Copyright (c) 2015年 花轮. All rights reserved.
//

import UIKit

class User: NSObject {
    var id:Int = 0
    var name: String?
    var profile_image_url: String?{
        didSet{
            iconURL = NSURL(string: profile_image_url!)
        }
    }
    
    var iconURL: NSURL?
// 认证类型 -1：没有认证，0，认证用户，2,3,5: 企业认证，220: 草根明星（达人）
    var verified_type: Int = -1
    
    // 1～6 一共6级会员
    var mbrank: Int = 0
    
    // 认证图标的计算型属性
    var renzhengImage: UIImage?
        {
        switch verified_type
        {
        case 0:
            return UIImage(named: "avatar_vip")
        case 2,3,5:
            return UIImage(named: "avatar_enterprise_vip")
        case 220:
            return UIImage(named: "avatar_grassroot")
            
        default:
            return nil
        }
    }
        // 会员图标
        var vipImage: UIImage?
        {
            if mbrank > 0 && mbrank < 7
            
            {
                let imgName = "common_icon_membership_level\(mbrank)"
                return UIImage(named: imgName)
            }
                return nil
        }
    
    private static let properties = ["id", "name", "profile_image_url", "mbrank", "verified_type"];
    
    init(dict: [String: AnyObject]) {
        super.init()
        
        for k in User.properties
        {
            if dict[k] != nil
            {
                setValue(dict[k], forKeyPath: k)
            }
        }
    }
}
